local FightBuff = require("gameLogic.fight.fightBuff.FightBuff")
local BuffShareHurt = class("BuffShareHurt")
local Hurt = require("gameLogic.fight.fightHurtStrategy.Hurt")

function BuffShareHurt:ctor(config, entity, whoEntity, shareEntitys)
    self._shareEntitys = shareEntitys
    BuffShareHurt.super.ctor(self, config, entity, whoEntity)
end

function BuffShareHurt:_initListener()
end

function BuffShareHurt:getShareNum()
    local count = 0
    for i = 1, #self._shareEntitys do
        if not self._shareEntitys[i]:isDie() then
            count = count + 1
        end
    end
    return count
end

function BuffShareHurt:shareHurt(hurt, battleReport)
    for i = 1, #self._shareEntitys do
        if not self._shareEntitys[i]:isDie() then
            self._shareEntitys[i]:simpleHurt(hurt, battleReport)
            battleReport:addSubHurt(hurt, self._entity, self._shareEntitys[i])
        end
    end
end

function BuffShareHurt:_excute(battleReport, hurt)
    local nums = self:getShareNum()
    local value = math.floor(hurt.value / (nums + 1))
    hurt.value = hurt.value - value * nums
    local newHurt = Hurt.new(value, hurt.isCrit, hurt.element, false, self._entity)
    self:shareHurt(newHurt, battleReport)
end

function BuffShareHurt:resetbuff()
end

return BuffShareHurt
